<template>
  <div>
    <el-table
      v-loading="loading"
      :data="postList"
    >
      <el-table-column label="类型" align="center" prop="name"/>
      <el-table-column
        label="申请时间"
        align="center"
        prop="num"
      />
      <el-table-column
        label="状态"
        align="center"
        prop="num"
      />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleViewTeam(scope.row)"
            v-hasPermi="['system:team:list']"
          >详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {
  listStagnationPoint,
  getStagnationPoint,
  delStagnationPoint,
  addStagnationPoint,
  updateStagnationPoint
} from "@/api/system/stagnation_point";

export default {
  name: "StagnationPoint",
  dicts: ['sys_stagnation_type'],
  components: {},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 岗位表格数据
      postList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        postCode: undefined,
        postName: undefined,
        status: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      paramId: 0,
      teamVisible: false,
      param: null,
      zhudianVisible: false,
      listVisible: false,
      schedulingVisible: false
    };
  },
  watch: {},
  created() {
    this.loading = false;
    // this.getList()
  },
  methods: {
    /** 查询岗位列表 */
    getList() {
      this.loading = true;
      listStagnationPoint(this.queryParams).then(response => {
        this.postList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.postId)
      this.single = selection.length != 1
      this.multiple = !selection.length
    },
    // 更多操作触发
    handleCommand(command, row) {
      switch (command) {
        case "handleDataScope":
          // 班次管理
          this.banciFn(row);
          break;
        case "handleDataEdit":
          // 编辑
          this.handleUpdate(row);
          break;
        case "handleAuthDetel":
          // 删除
          this.handleDelete(row);
          break;
        default:
          break;
      }
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.paramId = 0
      this.zhudianVisible = true
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.paramId = row.id
      this.zhudianVisible = true
    },
    paibanFn(row) {
      this.param = JSON.parse(JSON.stringify(row))
      this.schedulingVisible = true
    },
    banciFn(row) {
      this.param = JSON.parse(JSON.stringify(row))
      this.listVisible = true
    },
    handleViewTeam(row) {
      this.param = JSON.parse(JSON.stringify(row))
      this.teamVisible = true
    },
    // 用户状态修改
    handleStatusChange(row) {
      let text = row.status === "0" ? "启用" : "停用";
      this.$modal.confirm('确认要"' + text + '""' + row.name + '"执勤点吗？').then(function () {
        return updateStagnationPoint({id: row.id, status: row.status});
      }).then(() => {
        this.$modal.msgSuccess(text + "成功");
      }).catch(function () {
        row.status = row.status === "0" ? "1" : "0";
      });
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != undefined) {
            updateStagnationPoint(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addStagnationPoint(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.$modal.confirm('是否确认删除执勤点为"' + row.name + '"的数据项？').then(function () {
        return delStagnationPoint(row.id);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/stagnation_point/export', {
        ...this.queryParams
      }, `post_${new Date().getTime()}.xlsx`)
    },
    /** 排序触发事件 */
    handleSortChange(column, prop, order) {
      this.queryParams.orderByColumn = column.prop;
      this.queryParams.isAsc = column.order;
      this.getList();
    }
  }
};
</script>
<style lang="scss" scoped>
.points-map {
  height: 400px;
}

.points-map__tip {
  color: #010101;
  font-size: 14px;
  font-weight: 700;
  line-height: 20px;
}

.point-radius {
  margin-bottom: 20px;
  padding: 0 20px;

  .point-radius__len {
    margin-top: 10px;
    display: flex;
    display: -webkit-flex;
    justify-content: space-between;
    color: #010101;
    font-size: 14px;
    font-weight: 400;
    line-height: 20px;
  }
}

.mapBox {
  margin-bottom: 20px;
  padding: 0 20px;
}
</style>
